<?php

namespace app\admin\model\product;

use think\Model;


class Attr extends Model
{

    

    

    // 表名
    protected $name = 'product_attr';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'deploy_type_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            if (!$row['weigh']) {
                $pk = $row->getPk();
                $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
            }
        });
    }



    public function getDeployTypeList()
    {
        return ['1' => __('cpu'), '2' => __('主板'), '3' => __('显卡'), '4' => __('内存'), '5' => __('硬盘')
            , '6' => __('电源'), '7' => __('散热'), '8' => __('机箱'), '9' => __('显示器'), '10' => __('配件'),
            '11' => __('外设')];
    }


    public function getDeployTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['deploy_type']) ? $data['deploy_type'] : '');
        $list = $this->getDeployTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }






}
